// JavaScript Document
var emailRegxp	  =	/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;	
function validateReg()
{
	
	
	var name = $('#fname').val();
	var lname = $('#lname').val();
	var email = $('#email').val();
	var username = $('#username').val();
	var passwd = $('#passwd').val();
	var passwd_rem = $('#passwd_rem').val();
	var mobile_num = $('#mobile_num').val();
	var business_name = $('#business_name').val();
	var security_code = $('#security_code').val();
	
	var mand_flag = 1;


	if(name == "") {
		mand_flag = 0;
		$('#name').addClass('mandatory_field');
	}
	if(lname == "") {
		mand_flag = 0;
		$('#lname').addClass('mandatory_field');
		
	}

     if(username == "") {
		mand_flag = 0;
		$('#username').addClass('mandatory_field');
	}

	if(passwd == "") {
		mand_flag = 0;
		$('#passwd').addClass('mandatory_field');
	}
		
	if(passwd_rem == "") {
		mand_flag = 0;
		$('#passwd_rem').addClass('mandatory_field');
	}

	if(mobile_num == "") {
		mand_flag = 0;
		$('#mobile_num').addClass('mandatory_field');
	}
	
	if(business_name == "") {
		mand_flag = 0;
		$('#business_name').addClass('mandatory_field');
	}
	
	if(security_code == "") {
		mand_flag = 0;
		$('#security_code').addClass('mandatory_field');
	}

	if(mand_flag == 0) {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('All fields Are Mandatory');
		$('#error_msg').fadeOut(3000);
	}
	
	
	if(mand_flag == 1) {
		if(email != "" && email.search(emailRegxp)== -1) {
			alert('Please enter a valid email address');
			$('#email').focus();
		}
		else {
			$('#process').val('add_user');	
			document.reg_user.method="post";
			
			document.reg_user.action="application/action.php";
			document.reg_user.submit();
		}
	}
	return false;
}

function ForValidate()
{
	
	var email = $('#email').val();
		
	var mand_flag = 1;


	if(email == "") {
		mand_flag = 0;
		$('#email').addClass('mandatory_field');
	}
	

	if(mand_flag == 0) {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('E mail id Required');
		$('#error_msg').fadeOut(3000);
	}
	
	
	if(mand_flag == 1) {
		if(email != "" && email.search(emailRegxp)== -1) {
			alert('Please enter a valid email address');
			$('#email').focus();
		}
		else {
			$('#process').val('forgetid');	
			document.forpas.method="post";
			
			document.forpas.action="application/action.php";
			document.forpas.submit();
		}
	}
	return false;
}


function signin()
{
	
	var email = $('#email').val();
	var password = $('#password').val();
	var mand_flag = 1;


	if(email == "") {
		mand_flag = 0;
		$('#email').addClass('mandatory_field');
	}
	if(password == "") {
		mand_flag = 0;
		$('#password').addClass('mandatory_field');
	}
	

	if(mand_flag == 0) {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('All Fields Are Required');
		$('#error_msg').fadeOut(3000);
	}
	
	
	if(mand_flag == 1) {
		if(email != "" && email.search(emailRegxp)== -1) {
			alert('Please enter a valid email address');
			$('#email').focus();
		}
		else {
		
			$('#process').val('log');	
			
			document.login.method="post";
			document.login.action="application/action.php";
			document.login.submit();
		}
	}
	return false;
}

function validateContact()
{
	
	
	var email = $('#email').val();
	var name = $('#name').val();
	var securitycode = $('#securitycode').val();
	
	//var mand_flag = 1;


	if(email == "") {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('Please enter the eMail Address');
		$('#error_msg').fadeOut(3000);
		$('#email').focus();
		return false;
	}
	else {
		
		var valid_email_address = /[\S]+@[\S]+\.[\w]{2}/;
		if(email.search(valid_email_address )== -1) {
		
			$('#error_msg').fadeIn(3000);
			$('#error_msg').html("Please enter the valid eMail Address");
			$('#error_msg').fadeOut(3000);
			$('#email').focus();
			return false;
		}	
	}
	
	if(name == "") {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('Please enter the Name');
		$('#error_msg').fadeOut(3000);
		$('#name').focus();
		return false;
	}
	
	if(securitycode == "") {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('Please enter the securitycode');
		$('#error_msg').fadeOut(3000);
		$('#securitycode').focus();
		return false;
	}

	$('#process').val('add_contact');	
	$("#form_action").val("action");
	document.contact.action = "application/action.php";
	document.contact.submit();	
	
	
	$.post("application/action.php",{ process:'add_contact', vendor_id:vendor_id },function(getResult){
		if(getResult == 1) {
			$("#mail_img_"+vendor_id).attr("src", server_path+'public/images/mail_enable.png');
		}
		else {
			$("#mail_img_"+vendor_id).attr("src", server_path+'public/images/mail_disable.png');
		}
	});
}

function ValidateForm1()
{
	
	var title = $('#title').val();
	var desc = $('#desc').val();
	var searchtittle = $('#searchtittle').val();
	var summary = $('#summary').val();
	var cdate = $('#cdate').val();
	var cname = $('#cname').val();
	var email = $('#email').val();
	
	
	var mand_flag = 1;


	if(title == "") {
		mand_flag = 0;
		$('#title').addClass('mandatory_field');
	}
	
	if(desc == "") {
		mand_flag = 0;
		$('#desc').addClass('mandatory_field');
	}
	if(searchtittle == "") {
		mand_flag = 0;
		$('#searchtittle').addClass('mandatory_field');
	}
	if(summary == "") {
		mand_flag = 0;
		$('#summary').addClass('mandatory_field');
	}
	if(cdate == "") {
		mand_flag = 0;
		$('#cdate').addClass('mandatory_field');
	}
	if(cname == "") {
		mand_flag = 0;
		$('#cname').addClass('mandatory_field');
	}
	if(email == "") {
		mand_flag = 0;
		$('#email').addClass('mandatory_field');
	}

	if(mand_flag == 0) {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('* Marked fields are Required ');
		$('#error_msg').fadeOut(3000);
	}
	
	
	if(mand_flag == 1) {
			if(email != "" && email.search(emailRegxp)== -1) {
			alert('Please enter a valid email address');
			$('#email').focus();
		}
		else {
			document.theForm.method="post";
			document.theForm.submit();
		}
	}
	return false;
}
function ValidateForm2()
{
	
	var Category = $('#Category').val();
	var txtHint1 = $('#txtHint1').val();
	var searchtittle = $('#searchtittle').val();
	var summary = $('#summary').val();
	var location = $('#location').val();
	var worktype = $('#worktype').val();
	
	
	var mand_flag = 1;


	if(Category == 0) {
		mand_flag = 0;
		$('#Category').addClass('mandatory_field');
	}
	
	if(txtHint1 == 0) {
		mand_flag = 0;
		$('#txtHint1').addClass('mandatory_field');
	}
	if(searchtittle == "") {
		mand_flag = 0;
		$('#searchtittle').addClass('mandatory_field');
	}
	if(summary == "") {
		mand_flag = 0;
		$('#summary').addClass('mandatory_field');
	}
	if(location == 0) {
		mand_flag = 0;
		$('#location').addClass('mandatory_field');
	}
	if(worktype == 0) {
		mand_flag = 0;
		$('#worktype').addClass('mandatory_field');
	}

	if(mand_flag == 0) {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('* Marked fields are Required ');
		$('#error_msg').fadeOut(3000);
	}
	
	
	if(mand_flag == 1) {
		
			document.thisForm.method="post";
			document.thisForm.submit();
		}
	
	return false;
}

function apply_job()
{
	
	var my_name = $('#my_name').val();
	
	var email = $('#my_email').val();
	
	var attach = $('#attach').val();
		
	var mand_flag = 1;


	if(my_name == "") {
		mand_flag = 0;
		$('#my_name').addClass('mandatory_field');
	}
	if(email == "") {
		mand_flag = 0;
		$('#my_email').addClass('mandatory_field');
	}
	if(attach == "") {
		mand_flag = 0;
		$('#attach').addClass('mandatory_field');
	}
	
	if(mand_flag == 0) {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('* Marked fields are Required ');
		$('#error_msg').fadeOut(3000);
	}
	
	
	if(mand_flag == 1) {
			if(email != "" && email.search(emailRegxp)== -1) {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('Please enter a valid email address ');
		$('#error_msg').fadeOut(3000);
			
			$('#email').focus();
		}
		var checkimg = attach.toLowerCase();
		if (attach != "" && !checkimg.match(/(\.doc|\.docx|\.pdf|\.DOC|\.DOCX|\.PDF)$/)) {
			mand_flag = 0;
			$('#error_msg').fadeIn(3000);
			$('#error_msg').html("Please select DOC,DOCX or PDF Files");
			$('#my_resume').focus();
			
		}
		
		else {
			$('#process').val('sendjobmail');	
	        document.applyjob.action = "application/action.php";
			document.applyjob.method="post";
			document.applyjob.submit();
		}
	}
	return false;
}

function validateBannerAdverts()
{
	var email = $('#email').val();
	var name = $('#name').val();
	var advt_item = $('#advt_item').val();
	var advt_days = $('#advt_days').val();
	
	//var mand_flag = 1;


	if(email == "") {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('Please enter the eMail Address');
		$('#error_msg').fadeOut(3000);
		$('#email').focus();
		return false;
	}
	else {
		
		var valid_email_address = /[\S]+@[\S]+\.[\w]{2}/;
		if(email.search(valid_email_address )== -1) {
		
			$('#error_msg').fadeIn(3000);
			$('#error_msg').html("Please enter the valid eMail Address");
			$('#error_msg').fadeOut(3000);
			$('#email').focus();
			return false;
		}	
	}
	
	if(name == "") {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('Please enter the Name');
		$('#error_msg').fadeOut(3000);
		$('#name').focus();
		return false;
	}
	
	if(advt_item == "") {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('Please enter the Adverts Item');
		$('#error_msg').fadeOut(3000);
		$('#advt_item').focus();
		return false;
	}
	
	if(advt_days == "") {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('Please enter the Adverts Run Time');
		$('#error_msg').fadeOut(3000);
		$('#advt_days').focus();
		return false;
	}
	
	if($('#read_terms').attr('checked') == false) {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('Accept our terms and agreement');
		$('#error_msg').fadeOut(3000);
		return false;		
	}
	
	$('#process').val('add_query');	
	document.contact.action = "application/action.php";
	document.contact.submit();	
}
function validateproduct()
{
	
	var gadget = $('#gadget').val();
	var make = $('#make').val();
	var spec = $('#spec').val();
	var Quality = $('#Quality').val();
	var price = $('#price').val();
	var upload = $('#upload').val();
	
	var mand_flag = 1;


	if(gadget == 0) {
		mand_flag = 0;
		$('#gadget').addClass('mandatory_field');
		
	}
	
	if(make == "") {
		mand_flag = 0;
		$('#make').addClass('mandatory_field');
	}
	if(spec == "") {
		mand_flag = 0;
		$('#spec').addClass('mandatory_field');
	}
	if(Quality == 0) {
		mand_flag = 0;
		$('#Quality').addClass('mandatory_field');
	}
	if(price == "") {
		mand_flag = 0;
		$('#price').addClass('mandatory_field');
	}
	if(mand_flag == 0) {
		$('#error_msg').fadeIn(3000);
		$('#error_msg').html('* Marked fields are Required ');
		$('#error_msg').fadeOut(3000);
	}
	
	
	if(mand_flag == 1) {
		var checkimg = upload.toLowerCase();
		if (upload != "" && !checkimg.match(/(\.jpg|\.JPG|\.jpeg|\.JPEG|\.png|\.PNG|\.GIF|\.gif)$/)) {
			mand_flag = 0;
			$('#error_msg').fadeIn(3000);
			$('#error_msg').html("Please select JPG,GIF or PNG File");
			$('#error_msg').fadeOut(3000);
			$('#upload').focus();
			
		}
	else
	{
		
	$('#process').val('sellproduct');	
	        document.product.action = "application/action.php";
			document.product.method="post";
			document.product.submit();
		
	}}
	return false;
}

function sellbooks()
{
	
	var tit = $('#tit').val();
	var author = $('#author').val();
	var desc = $('#desc').val();
	var isbn = $('#isbn').val();
	var price = $('#price').val();
	var upload = $('#upload').val();
	
	var mand_flag = 1;

	if(tit == "") {
	mand_flag = 0;
	$('#tit').addClass('mandatory_field');
	}
		
	if(author == "") {
	mand_flag = 0;
	$('#author').addClass('mandatory_field');
	}
	if(desc == "") {
	mand_flag = 0;
	$('#desc').addClass('mandatory_field');
	}
	if(isbn == "") {
	mand_flag = 0;
	$('#isbn').addClass('mandatory_field');
	}
	if(price == "") {
	mand_flag = 0;
	$('#price').addClass('mandatory_field');
	}
	
	if(mand_flag == 0) {
	$('#error_msg').fadeIn(3000);
	$('#error_msg').html('* Marked fields are Required ');
	$('#error_msg').fadeOut(3000);
	}
	
	if(mand_flag == 1) {
		var checkimg = upload.toLowerCase();
		if (upload != "" && !checkimg.match(/(\.jpg|\.JPG|\.jpeg|\.JPEG|\.png|\.PNG|\.GIF|\.gif)$/)) {
			mand_flag = 0;
			$('#error_msg').fadeIn(3000);
			$('#error_msg').html("Please select JPG,GIF or PNG File");
			$('#error_msg').fadeOut(3000);
			$('#upload').focus();
			
		}
	else
	{
		$('#process').val('sellbook');	
	
	       document.sellbook.action = "application/action.php";
			document.sellbook.method="post";
			document.sellbook.submit();
		
	}}
	return false;
}
		
function validateSearch()
{
	var txt_search = $('#txt_search').val();

	if(txt_search != "" && txt_search != 'search') {
		document.frmSearch.method="post";
		document.frmSearch.action="index.php?page=search";
		document.frmSearch.submit();	
	}
	
	return false;
}	
function vote(eid)
{
	
	var val = document.vote_form.univ_id.value=eid;
	document.vote_form.action = "application/action.php";
	document.vote_form.method="post";
	document.vote_form.submit();
}	

		
	